#ifndef QLIB_QEDACOMPONENT_H
#define QLIB_QEDACOMPONENT_H

#include <QHash>
#include <QObject>

QT_FORWARD_DECLARE_CLASS(QDomDocument)
QT_FORWARD_DECLARE_CLASS(QDomElement)
QT_FORWARD_DECLARE_CLASS(QMdiSubWindow)

class LibraryTreeItem;
class QedaLibrary;

class QedaComponent : public QObject
{
    Q_OBJECT
public:
    enum ComponentFlag
    {
        SymbolFlag = 0x1,
        PatternFlag = 0x2,
        SymbolPatternFlags = SymbolFlag | PatternFlag
    };
    Q_DECLARE_FLAGS(ComponentFlags, ComponentFlag)
    explicit QedaComponent(QObject *parent = 0);
    ~QedaComponent();

    const QString &name() const { return m_name; }
    void setName(const QString &name);
    QString displayName() const;

    const QString &reference() const { return m_reference; }
    void setReference(const QString &reference);

    const QString &group() const { return m_group; }
    void setGroup(const QString &group);

    QedaLibrary *library();
    void setLibrary(QedaLibrary *newLibrary);

    ComponentFlags flags(ComponentFlags mask) const { return m_flags & mask; }
    void setFlags(ComponentFlags flags, ComponentFlags mask);

    void fromXml(const QDomElement& elem);
    void toXml(QDomDocument &doc, QDomElement &elem);

    void update();
    void setModified(bool modified);
    bool isModified() { return m_modified; }

    LibraryTreeItem *treeItem(int mode) { return m_treeItem.value(mode); }
    void setTreeItem(int mode, LibraryTreeItem *treeItem) { m_treeItem[mode] = treeItem; }

    QMdiSubWindow *win() { return m_win; }
    void setWin(QMdiSubWindow *win) { m_win = win; }
    void closeWin(bool quietMode = false);

signals:
    void componentUpdated(QedaComponent *copmponent);
    void displayNameUpdated(const QString &displayName);

public slots:
private:
    QString                      m_name;
    QString                      m_reference;
    QString                      m_group;
    ComponentFlags               m_flags;
    bool                         m_modified;

    QHash<int,LibraryTreeItem*>  m_treeItem;
    QMdiSubWindow               *m_win;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(QedaComponent::ComponentFlags)

typedef QList<QedaComponent*> QedaComponentList;

#endif // QLIB_QEDACOMPONENT_H
